<template>
    <div class="todo-footer">
        <label>
            <input type="checkbox" v-model="isCheckAll"/>
        </label>
        <span>
            <span>已完成{{completeCount}}</span> / 全部{{totalCount}}
        </span>
        <button class="btn btn-danger" v-show="completeCount>0" @click="delCompleteTodos"> 清除已完成任务</button>
    </div>
</template>

<script>
    import {mapGetters} from 'vuex'
    export default {
        name: "TodoFooter",
        computed:{
            ...mapGetters(['totalCount', 'completeCount']),
            isCheckAll:{
                get(){  //初始化显示数据
                    return this.$store.getters.isCheckAll
                },
                set(isChecked){ /*改变选中的状态,isChecked是当前checkbox最新的值*/
                    //this.selectAllTodos(value)
                    this.$store.dispatch('selectAllTodos',isChecked);
                }
            }
        },
        methods:{
            delCompleteTodos(){
                if(window.confirm('确定清除已完成的吗?')) {
                    this.$store.dispatch('deleteCompleteTodos')
                }
            }
        }
    }
</script>

<style scoped>
    .todo-footer {
        height: 40px;
        line-height: 40px;
        padding-left: 6px;
        margin-top: 5px;
    }

    .todo-footer label {
        display: inline-block;
        margin-right: 20px;
        cursor: pointer;
    }

    .todo-footer label input {
        position: relative;
        top: -1px;
        vertical-align: middle;
        margin-right: 5px;
    }

    .todo-footer button {
        float: right;
        margin-top: 5px;
    }

</style>